<template>
	<view :style="{height:`${list.length>4?'300rpx':'138rpx'}`}" class="tab-box">
		<swiper class="tab-swiper">
			<swiper-item v-for="(item,index) in tabList" :key="index" class="tab-swiper-item">
				<view class="tab-swiper-view">
					<view @click="toPage(tab)" v-for="(tab,tabIndex) in item" :key="tabIndex"
						class="tab-swiper-view-item">
						<image :src="tab.icon" mode=""></image>
						<view class="">{{tab.name}}</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import util from '@/common/util'
	export default {
		props: {
			list: Array
		},
		data() {
			return {
				tabList: [],
				current: 0,
				tabUrl: 'https://qiyeji.oss-cn-beijing.aliyuncs.com/pet/tab-1.png',
			}
		},
		watch: {
			list: {
				handler(val) {
					this.tabList = util.twoArray(val, 8)
				},
				immediate: false,
				deep: true,
			}
		},
		methods: {
			handleChange(e) {
				this.current = e.detail.current;
			},
			toPage(item) {
				if (item.path.includes('/pages/product/index/index') || item.path.includes('/pages/pet/auth/index')) {
					if (item.path.indexOf('?') < 0) {
						uni.$emit('handlePath', item.path)
					} else {
						let currentArr = item.path.split('?')
						var paramObj = {}
						if (currentArr[1].indexOf('&') < 0) {
							var params = currentArr[1].split('=')
							paramObj[params[0]] = params[1]
						} else {
							var params = currentArr[1].split('&')
							for (var i in params) {
								var param = params[i].split('=')
								paramObj[param[0]] = param[1]
							}
						}
						uni.$emit('handlePath', currentArr[0], paramObj)
					}
				} else {
					var path = item.path
					if (path.indexOf('=') > 0 && !path.split('=')[1]) {
						path = path + item.bizId
					}
					uni.navigateTo({
						url: path
					})

				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.tab-box {
		width: 702rpx;
		// height: 300rpx;
		margin: 56rpx auto 0;

		// background: red;
		.tab-swiper {
			width: 100%;
			height: 100%;

			.tab-swiper-item {
				width: 100%;
				height: 100%;

				.tab-swiper-view {
					width: 100%;
					height: 100%;
					display: flex;
					flex-flow: row wrap;

					.tab-swiper-view-item {
						width: 25%;
						margin-bottom: 32rpx;
						display: flex;
						flex-direction: column;
						align-items: center;

						image {
							width: 80rpx;
							height: 80rpx;
							border-radius: 50%;
						}

						view {
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 26rpx;
							color: var(--h1Color);
							line-height: 37rpx;
							text-align: center;
							margin-top: 16rpx;
							overflow: hidden;
						}
					}
				}
			}
		}
	}
</style>